package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark5Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

public class Mark5 extends BaseMark {

    LayoutWatermark5Binding binding;

    public Mark5(@NonNull Context context) {
        super(context);
    }

    public Mark5(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark5(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark5Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark5Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
        if (type == 0) {
            hideView(binding.binding10, binding.binding12, binding.binding14, binding.binding16);
        }
    }

    @Override
    public void update() {
        setText(binding.binding2, "title5", "会议记录", binding.binding1);
        setText(binding.binding5, "time5", "13:30", binding.binding4);
        setTime(binding.binding5, new SimpleDateFormat("HH:mm"));
        if (!setTime(binding.binding7, new SimpleDateFormat("yyyy.MM.dd"))) {
            binding.binding7.setText("2023.03.09");
        }
        if (!setWeek(binding.binding6)) {
            binding.binding6.setText("星期四");
        }
        setText(binding.binding9, "didan5", "在这里", binding.binding8);
        setText(binding.binding11, "zhuchiren5", binding.binding10);
        setText(binding.binding13, "renyuan5", binding.binding12);
        setText(binding.binding15, "renshu5", binding.binding14);
        setText(binding.binding17, "beizhu5", binding.binding16);
        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title5", "标题"));
        list.add(new EditItem("time5", "时间", true));
        list.add(new EditItem("didian5", "地点"));
        list.add(new EditItem("zhuchiren5", "主持人"));
        list.add(new EditItem("renyuan5", "与会人员"));
        list.add(new EditItem("renshu5", "与会人数"));
        list.add(new EditItem("beizhu5", "备注"));
        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding5, new SimpleDateFormat("HH:mm"));
            setTime(binding.binding7, new SimpleDateFormat("yyyy.MM.dd"));
            setWeek(binding.binding6);
        } else {
            super.onValueChange(item);
        }
    }
}
